define(function (require, exports, module) {

    var axios = require('lib/axios.js');

    function GetTicket() {
        //从 sessionstory取
        return "13DDFGKLKFDJFL";
    }

    axios.interceptors.request.use(function (config) {
        // 在发送请求之前做些什么
        console.log(config);

        //发送前把当时ticket带入
        if (config.method == "get") {
            config.url = (config.url + (config.url.indexOf('?') > -1 ? "&" : "?") + "token=" + GetTicket());
        } else if (config.methods == "post") {
            config.data = config.data || {};
            config.data.ticket = GetTicket();
        }

        return config;
    }, function (error) {
        //对请求错误做些什么

        return Promise.reject(error);
    });

    axios.defaults.baseURL = baseSiteUrl;


    // 添加响应拦截器
    axios.interceptors.response.use(function (response) {
        // 对响应数据做点什么
        return response;
    }, function (error) {
        // 对响应错误做点什么
        console.log(error);
        //写日志
        return Promise.reject(error);
    });
    var VueComponent = new Vue({
        el: '#app',
        data: {
            templateList: [],
            template_id: '',
            folder_path: '',//多模板扫描路径
            img_folder: '',//单模板扫描图片路径
            typeArr: [{
                value: '1',
                label: '多模板,只指定文件夹,批处理文件夹下所有PDF文件'
            }, {
                value: '2',
                label: '单模板,指定具体PDF文件,作为模板,生成多文件'
            }],
            type: '',
            templateListAfterFilter: [],
            loading: false,
        },
        mounted: function () {
            var thisVue = this;
            var url = "/templateFile/list.htmls";
            axios.get(url)
                .then(function (response) {
                    thisVue.templateList = response.data;
                    thisVue.type_select_change();
                    //thisVue.templateListAfterFilter = response.data;
                });
        },
        methods: {
            type_select_change: function (val) {

                if (val == undefined || val == "") {
                    this.templateListAfterFilter = _.filter(this.templateList, function (item) {
                        return true;
                    });
                    return;
                }

                if (val.toString() == "1") {
                    this.templateListAfterFilter = _.filter(this.templateList, function (item) {
                        return item.path != null && item.path.indexOf('.pdf') == -1;
                    });
                    this.template_id = '';
                } else if (val.toString() == "2") {
                    this.templateListAfterFilter = _.filter(this.templateList, function (item) {
                        return item.path != null && item.path.indexOf('.pdf') > -1;
                    });
                    this.template_id = '';
                }
            },
            template_select_change: function (selVal) {
                var thisVue = this;
                var arr = _.filter(thisVue.templateList, function (item) {
                    return item.id.toString() == selVal.toString();
                });
                thisVue.curTemplate = arr.length == 0 ? [] : arr[0];
            },
            create_go: function () {
                var url = baseSiteUrl + "templateFile/createFile.htmls";

                $.ajax({
                    type: 'POST',
                    url: url,
                    dataType: 'json',
                    data: {
                        templateId: this.template_id,
                        folderPath: this.folder_path,
                        type: this.type,
                        imgFolder: this.img_folder
                    },
                    success: function (res) {

                        toastr.success('操作成功');
                        // if (res.success) {
                        //     toastr.success('操作成功');
                        // }
                        // else {
                        //     toastr.error(res.msg);
                        // }
                    }
                })
            },
            form_reset: function () {
                this.template_file_id = '';
                this.filePath = "";
            }

        }

    });

});